package com.qingyu.print.member.controller;

import java.util.Arrays;
import java.util.Map;

//import org.apache.shiro.authz.annotation.RequiresPermissions;
import com.qingyu.common.utils.PageUtils;
import com.qingyu.common.utils.R;
import com.qingyu.print.member.annotation.DisableBaseResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.qingyu.print.member.entity.ImageEntity;
import com.qingyu.print.member.service.ImageService;
import org.springframework.web.multipart.MultipartFile;


/**
 * 
 *
 * @author qingyu
 * @email 1548686075@qq.com
 * @date 2021-08-03 16:16:40
 */
@RestController
@RequestMapping("member/image")
public class ImageController {

    @Autowired
    private ImageService imageService;

    /**
     * 用户注册时的头像上传
     */
    @PostMapping("/image")
    @DisableBaseResponse
    public String uploadImage(@RequestParam("file")MultipartFile file) throws Exception{
        if (file==null || file.isEmpty()) throw new Exception("File cannot be empty");
        return imageService.save(file);
    }


    /**
     * 列表
     */
    @RequestMapping("/list")
    //@RequiresPermissions("member:image:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = imageService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    //@RequiresPermissions("member:image:info")
    public R info(@PathVariable("id") String id){
		ImageEntity image = imageService.getById(id);

        return R.ok().put("image", image);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    //@RequiresPermissions("member:image:save")
    public R save(@RequestBody ImageEntity image){
		imageService.save(image);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
   //@RequiresPermissions("member:image:update")
    public R update(@RequestBody ImageEntity image){
		imageService.updateById(image);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    //@RequiresPermissions("member:image:delete")
    public R delete(@RequestBody String[] ids){
		imageService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
